/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.data.service.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import me.send.data.service.mapper.provider.AdvertProvider;
import me.send.data.service.pojo.Advert;

/**
 * @author maxmin
 *
 * @date 2015年9月24日 上午11:29:00
 */
public interface AdvertMapper {
	
	@Select(value="SELECT * FROM advert WHERE advertid=#{advertid}")
	@Results({
		@Result(column="original_price",property="originalPrice"),
		@Result(column="discount_price",property="discountPrice")
	})
	public Advert getAdvertById(int advertid);
	
	@Update(value="UPDATE advert SET isdelete=1 WHERE advertid=#{advertid}")
	public int deleteAdvertById(int advertid);
	
	@Update(value="INSERT INTO advert (type,status,starttime,endtime,original_price,discount_price,cityname,descption,url,picpath) "
			+ "values(#{type},#{status},#{starttime},#{endtime},#{originalPrice},#{discountPrice},#{cityname},#{descption},#{url},#{picpath})")
	public int addAdvert(Advert advert);
	
	@Update(value="UPDATE advert SET picpath=#{path} WHERE advertid=#{advertid}")
	public int updateAdvertPic(Map<String,Object> param);
	
	@Update(value="UPDATE advert SET type=#{type},status=#{status},starttime=#{starttime},"
			+ "endtime=#{endtime},original_price=#{originalPrice},discount_price=#{discountPrice},"
			+ "cityname=#{cityname},descption=#{descption},url=#{url} "
			+ "WHERE advertid=#{advertid}")
	public int updateAdvert(Advert advert);
	
	@SelectProvider(method="getAdvertList",type=AdvertProvider.class)
	@Results({
		@Result(column="original_price",property="originalPrice"),
		@Result(column="discount_price",property="discountPrice")
	})
	public List<Advert> getAdvertList(Map<String,Object> param);
	
	@SelectProvider(method="getAdvertCount",type=AdvertProvider.class)
	public int getAdvertCount(Map<String,Object> param);
	
	/**
	 * 禁用广告
	 * @return
	 * @author maxmin
	 * @date 2015年9月24日上午9:47:23
	 */
	@Update(value="UPDATE advert SET status=0 WHERE type=1")
	public abstract int updateAdvertStatusOfAll();
}
